/*
 * @Author: suxunying
 * @desc: user module
 * @Date: 2021-07-20 17:40:05
 * @LastEditors: suxunying
 * @LastEditTime: 2021-07-26 10:34:41
 * @FilePath: \bmp-poc\plat\src\store\modules\user.ts
 */
/* eslint no-shadow: ["error",{ "allow": ["state"] }] */
import shared from '@/shared';

export interface UserInfo {
    username: string,
}

interface State {
    userinfo: UserInfo | Record<string, never>,
}

const state: State = {
    userinfo: {
        username: '',
    },
};

const getters = {
    userinfo: (state: State) => state.userinfo,
};

const actions = {
    getInfo({ commit }: any, userinfo: UserInfo): Promise<any> {
        return new Promise((resolve, reject) => {
            commit('SET_USERINFO', userinfo);
            shared.dispatch('user/setUserinfo', userinfo);
            resolve(userinfo);
        });
    },
};

const mutations = {
    SET_USERINFO: (state: State, userinfo: UserInfo) => {
        state.userinfo = userinfo;
    },
};

export default {
    namespace: true,
    state,
    getters,
    actions,
    mutations,
};
